<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
	pageEncoding="UTF-8"%>
<%@ page
	import="java.util.Map,java.util.Map.Entry,swimv2gm.bl.domain.WorkRequestStatus"%>
<!DOCTYPE html>
<html>
<head>
<title>SWIMv2: Dettagli richiesta di lavoro</title>
<link rel="stylesheet" type="text/css"
	href="/SWIMv2gm/shared/global.css" />
</head>
<body>
	<div id="header">
		<h1>SWIMv2</h1>
	</div>
	<%@include file="/shared/menu.jsp"%>
	<div id="content">
		<h1>Dati richiesta</h1>
		<%
			Map<String,String> data = (Map<String,String>)request.getAttribute("data");
			if (data == null) {
		%>
		<div class="errorbox">Errore: richiesta non trovata.</div>
		<%
			}
			else {
		%>

		<table>
			<tr>
				<td>Data di invio</td>
				<td><%=data.get("date")%></td>
			</tr>
			<tr>
				<td>Campo di riferimento</td>
				<td><%=data.get("a_name")%></td>
			</tr>
			<tr>
				<td>Descrizione</td>
				<td><%=data.get("desc")%></td>
			</tr>

			<%
				long dest = Long.parseLong(data.get("dest_id"));
					if (request.getSession().getAttribute("user").equals(dest)) {
			%>
			<tr>
				<td>Mittente</td>
				<td><a
					href="/SWIMv2gm/user/Profile?uid=<%=data.get("mitt_id") != null ? data.get("mitt_id") : "mailto:" + data.get("mitt_name")%>"><%=data.get("mitt_name")%></a>
				</td>
			</tr>
			<%
				}
					else {
			%>
			<tr>
				<td>Destinatario</td>
				<td><a href="/SWIMv2gm/user/Profile?uid=<%=dest%>"><%=data.get("dest_name")%></a></td>
			</tr>
			<%
				}
			%>

			<tr>
				<%
					String status = data.get("status");
				%>
				<td>Stato</td>
				<td>
					<%
						if (WorkRequestStatus.PENDING.toString().equalsIgnoreCase(status)) {
					%><span class="pending">In attesa</span> <%
					 	}
				 		else if (WorkRequestStatus.ACCEPTED.toString().equalsIgnoreCase(status)) {
					%><span class="accept">Accettata</span> <%
					 	}
				 		else if (WorkRequestStatus.DECLINED.toString().equalsIgnoreCase(status)) {
					 %><span class="decline">Rifiutata</span> <%
 						}
					%>
				</td>
			</tr>
			<%
				if (WorkRequestStatus.PENDING.toString().equalsIgnoreCase(status)) {
			%>
			<tr>
				<td colspan="2">
					<%
						if (request.getSession().getAttribute("user").equals(dest)) {
					%> <a href="ProcessRequest?id=<%=data.get("id")%>&accepted=true"
					class="accept">Accetta</a>&nbsp; <a
					href="ProcessRequest?id=<%=data.get("id")%>&accepted=false"
					class="decline">Rifiuta</a> <%
 	}
 %>
				</td>
			</tr>
			<%
				}
			%>
		</table>
		<%
			}
		%>
	</div>
</body>
</html>